package jman.teemwork14;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Hashtable;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Vote2
 */
public class Vote2 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Vote2() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		if (UserService.session.getAttribute("userInfo")==null ) {
			response.sendRedirect("jmanLogin.teemwork14.html");
		} else {
			Hashtable h=(Hashtable)UserService.session.getAttribute("userInfo");
			String id=(String) h.get("id");
			final String ID="000000000000000004";
			UserService us=new UserService();
			boolean result=false;
			try {
				result = us.vote(id, ID);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if(result){
				response.sendRedirect("jmanVoteSuccess.html");
			}else{
				response.sendRedirect("jmanVoteFail.html");
			}
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
